package com.fll.fangyitask.service.impl;

import com.fll.fangyicommon.entity.task.UserTaskSubject;
import com.fll.fangyitask.dao.UserTaskSubjectDao;
import com.fll.fangyitask.service.UserTaskSubjectService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author fll
 * create 2023/3/9
 */
@Service
@Slf4j
public class UserTaskSubjectServiceImpl implements UserTaskSubjectService {

    @Autowired
    private UserTaskSubjectDao userTaskSubjectDao;

    /**
     * 插入关系表
     * @param userId
     * @param subjectId
     * @param taskId
     * @return
     */
    public Integer insert(Integer userId, Integer subjectId, Integer taskId){
        Integer num = userTaskSubjectDao.insert(userId,subjectId,taskId);
        if (num != 0){
            log.info("关系表：user_task_subject插入成功===>userId:{},===>subjectId:{},===>taskId:{}",userId,subjectId,taskId);
            return num;
        }
        log.info("关系表：user_task_subject插入失败");
        return null;
    }

    /**
     * 删除一条记录
     * @param userId
     * @param subjectId
     * @param taskId
     * @return
     */
    public Integer delete(Integer userId, Integer subjectId, Integer taskId){
        Integer num = userTaskSubjectDao.delete(userId,subjectId,taskId);
        if (num != 0){
            log.info("删除关系表记录：user_task_subject成功===>userId:{},===>subjectId:{},===>taskId:{}",userId,subjectId,taskId);
            return num;
        }
        log.error("删除关系表记录：user_task_subject失败===>userId:{},===>subjectId:{},===>taskId:{}",userId,subjectId,taskId);
        return -1;
    }

    /**
     * 判断关系表中是否有这个关系
     * @param userId
     * @param subjectId
     * @param taskId
     * @return
     */
    public Boolean isExist(Integer userId, Integer subjectId, Integer taskId){
        UserTaskSubject exist = userTaskSubjectDao.isExist(userId, subjectId, taskId);
        if (exist != null){
            log.info("存在关系,不能添加===>userId:{},===>subjectId:{},===>taskId:{}",userId,subjectId,taskId);
            return true;
        }
        log.error("不存在关系，可以添加===>userId:{},===>subjectId:{},===>taskId:{}",userId,subjectId,taskId);
        return false;
    }
}
